Structures: Initialisation
Pascal C/C++
w NO STANDARD PASCAL EQUIVALENT (BUT MANY DIALECTS ALLOW THIS)
w A C variable may be initialised when it is declared – e.g.
w int i = 3;
w char c = ‘A’;
w float a[3] = {1.0, 2.0, 3.0};
w struct
w{ char name[11];
w float gpa;
w} student = {“Smith”, 4.0};
NOTE: In C++, initialisation of a struct this way is not allowed if any field is of class type, requiring a constructor.

| In C++, initialisation of a struct this way is not allowed if any field is of class type, requiring a constructor. Thus, in particular, this example would not work correctly if name were declared as string, since string is a library class.